package com.ilop.sthome.mvp.present.device;

import com.example.common.mvp.BasePresenterImpl;
import com.ilop.sthome.data.greenDao.DeviceInfoBean;
import com.ilop.sthome.data.greenDao.RoomBean;
import com.ilop.sthome.mvp.contract.device.DeviceForRoomContract;
import com.ilop.sthome.utils.greenDao.utils.DeviceDaoUtil;
import com.ilop.sthome.utils.greenDao.utils.RoomDaoUtil;

import java.util.List;

/**
 * @author skygge
 * @date 2020/7/13.
 * GitHub：javofxu@github.com
 * email：skygge@yeah.net
 * description：
 */
public class DeviceForRoomPresenter extends BasePresenterImpl<DeviceForRoomContract.IView> implements DeviceForRoomContract.IPresent {

    @Override
    public void getRoomList() {
        List<RoomBean> mRoomList = RoomDaoUtil.getInstance().findAllRoomList();
        if (mRoomList != null) {
            mView.showRoomList(mRoomList);
        } else {
            mView.showEmptyView();
        }
    }

    @Override
    public void refreshByPosition(String deviceName, String roomId) {
        if (deviceName!=null && roomId!=null) {
            int mOwned  = DeviceDaoUtil.getInstance().findGatewayByDeviceName(deviceName).getOwned();
            if (mOwned ==1){
                mView.refreshRoom(roomId);
            }else {
                mView.refreshRoom("198");
            }
        }else {
            mView.refreshRoom(null);
        }
    }

    @Override
    public void findAllSubDevice() {
        List<DeviceInfoBean> mGateway = DeviceDaoUtil.getInstance().findAllGateway();
        List<DeviceInfoBean> mList = DeviceDaoUtil.getInstance().findAllSubDevice();
        if (mGateway.size() > 0 && mList.size() <= 0){
            mView.showLoadingView();
        }
    }
}
